package com.hx.dc.controllor;

import com.hx.dc.entity.DetailedOrder;
import com.hx.dc.entity.Refunds;
import com.hx.dc.entity.SimpleOrder;
import com.hx.dc.service.DetailOrderService;
import com.hx.dc.service.SimpleOrderService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2019/2/13 0013.
 */
@Controller
@RequestMapping("order")
public class OrderAction extends BaseAction {
    @Autowired
    private SimpleOrderService simpleOrderService;

    @Autowired
    private DetailOrderService detailOrderService;

    @RequestMapping("show")
    @ResponseBody//查询所有订单信息
    public Object show(String ordernum, DetailedOrder detailedOrder, Integer page, Integer rows) {
        detailedOrder.setOrderNum(ordernum);
        // System.out.println(ordernum);

        return this.getPage(detailOrderService.selectPage(detailedOrder,page, rows));
    }

    @RequestMapping("zhengjieshow")
    @ResponseBody
    public Object zhengjieshow(DetailedOrder detailedOrder, Integer page, Integer rows) {
        return this.getPage(detailOrderService.selectPage(detailedOrder,page, rows));
    }

    @RequestMapping("xian")
    @ResponseBody//建议订单条件查询
    public Object xian(SimpleOrder simpleOrder, Integer page, Integer rows) {


        return this.getPage(simpleOrderService.selectPage(simpleOrder,page, rows));
    }

    @RequestMapping("detail")
    @ResponseBody//点击的订单号查询所有详细菜品
    public Object detail(DetailedOrder detailedOrder, Integer page, Integer rows) {
        System.out.println(detailedOrder.getSimpleOrder());
        return this.getPage(detailOrderService.selectPage(detailedOrder,page, rows));
    }

    @RequestMapping("dan")
    @ResponseBody//单桌单桌结算
    public int dan(SimpleOrder simpleOrder,DetailedOrder detailedOrder) {
                //detailOrderService.execute();


        return detailOrderService.update(detailedOrder);//修改简易订单
    }

    @RequestMapping("zheng")
    @ResponseBody//整桌单桌结算
    public int zheng(DetailedOrder detailedOrder,SimpleOrder simpleOrder) {
        simpleOrder.setOrderNum(detailedOrder.getSimpleOrder());
        detailOrderService.update(detailedOrder);
        return simpleOrderService.jie(simpleOrder);
    }

    @RequestMapping("detailinsert")
    @ResponseBody//订单明细生成
    public int detailinsert(DetailedOrder detailedOrder) {
        int i=detailOrderService.insert(detailedOrder);
        if(i!=0){
//            WebSocket.sentMsg("success");
        }
        return  i;
    }

    @RequestMapping("simpleinsert")
    @ResponseBody//订单生成
    public int simpleinsert(SimpleOrder simpleOrder) {

        System.out.println("订单");
        return  simpleOrderService.insert(simpleOrder);
    }

    @RequestMapping("shen")
    @ResponseBody//整桌单桌结算
    public int shen(SimpleOrder simpleOrder) {

        return simpleOrderService.update(simpleOrder);
    }

    @RequestMapping("dantui")
    @ResponseBody//整桌单桌结算
    public int dantui(DetailedOrder detailedOrder) {
        return detailOrderService.dantui(detailedOrder);
    }

    @RequestMapping("shanchu")
    @ResponseBody//整桌单桌结算
    public int shanchu(SimpleOrder simpleOrder) {
        return simpleOrderService.delete(simpleOrder);
    }


    @RequestMapping("oper")
    @ResponseBody//点击的订单号查询所有详细菜品
    public Object oper(DetailedOrder detailedOrder, String id, Integer state) {
        detailedOrder.setOrderNum(id);
        detailedOrder.setOrderState(state);
        int i = detailOrderService.updateOrder(detailedOrder);
        if(i!=0){
//            WebSocket.sentMsg("success");
        }
        return null;
    }
    @RequestMapping("selectDetail")
    @ResponseBody//点击的订单号查询所有详细菜品
    public Object selectDetail(DetailedOrder detailedOrder, Integer page, Integer rows) {
        return this.getPage(detailOrderService.selectDetailList(detailedOrder,page, rows));
    }
}
